package com.lzx.lizhenxing.common.utils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class DateUtils {

    /**
     * 获取当前日期的年月字符串
     *
     * @return
     */
    public static String getYearAndMonth() {
        LocalDate localDate = LocalDate.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMM");
        return dateTimeFormatter.format(localDate);
    }

    /**
     * 格式化日期
     *
     * @param format
     * @return
     */
    public static String dateFormat(String format) {
        LocalDate localDate = LocalDate.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);
        return dateTimeFormatter.format(localDate);
    }

    /**
     * 得到上一天的日期字符串
     *
     * @param format
     * @return
     */
    public static String lastDayStr(String format) {
        LocalDate localDate = LocalDate.now().minusDays(1L);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);
        return dateTimeFormatter.format(localDate);
    }

    /**
     * 获取当前日期的日
     *
     * @return
     */
    public static int getDay() {
        return LocalDate.now().getDayOfMonth();
    }
}
